package app.TouTiao;

import java.text.SimpleDateFormat;
import java.util.Date;

import qiurank.Log;
import qiurank.PaFather;
import qiurank.PaHandle;
import qiurank.ThreadManage;

/**
 * Created by Administrator on 2016/1/8.
 */
public class TouTiaoHandle implements PaHandle {
    @Override
    public void handle(PaFather paFather, ThreadManage threadManage) {
        TouTiaoPa pa=(TouTiaoPa)paFather;
        Filter plan=(Filter)pa.getUrlManage().plan;
        if(pa.getContentType()!=null&&pa.getContentType().contains("application/json")){
            pa.getAllJsonUrl();
        }else {
            pa.getAllUrl();
        }
        if (plan.doPlanPaingUrl(pa.getUrl())) {
            //Log.console("url:"+noPa.url+",正在抓取内容标题:" + pa.getContentTitle()+"--评论数:"+pa.getCommentNums()+"--创建时间:"+pa.getContentCreateTime()+","+new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(pa.getContentCreateTime())));
            //Log.console("抓取内容:"+pa.getContent());
                pa.getAllUrl();
                ArticleObject articleObject = new ArticleObject();
                articleObject.create_time = pa.getContentCreateTime();
                articleObject.create_time_str = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(articleObject.create_time));
                articleObject.commentnums = pa.getCommentNums();
                articleObject.url = pa.getUrl();
                if (plan.doPlanFilterArticle(articleObject)) {
                    //Log.console("抓取内容:"+pa.getContent());
                    articleObject.from = pa.getFrom();
                    articleObject.content =pa.getContent();
                    articleObject.title =pa.getContentTitle();
                    if (plan.doPlanFilterKeyWord(articleObject.content)) {
                        Log.console("url:" + articleObject.url + ",标题:" + articleObject.title + "来自:" + articleObject.from + ",create_time:" + articleObject.create_time_str + ",评论:" + articleObject.commentnums);
                    }
                }

        } else {
            Log.show("收集连接完毕....");
        }
        Log.console("待爬取:" + pa.getUrlManage().getNoUrlList().size() + ",已爬取:" + pa.getUrlManage().getYesUrlCount());
    }
}
